<template>
    <div>
    <h2>结算类别管理</h2>
        <el-row type="flex" justify="left">
                <el-col :span="24" class="searchHeader">
                    <el-col :span="5">
                    <el-input placeholder="类别名称" v-model="keyword" clearable></el-input>
                    </el-col>
                    <el-col :span="4">
                        <el-button type="primary" icon="el-icon-search" @click="getList()" style="margin-left: 15px;">搜索类别</el-button>
                    </el-col>
                </el-col>
                <el-button type="danger" icon="el-icon-add-location" style="margin-left: 15px;" @click="dialogFormVisible = true">添加结算类别</el-button>
        </el-row>
        <el-table
            ref="multipleTable"
            :data="list"
            tooltip-effect="dark"
            style="width: 100%; margin-top: 2%"
            border
        >
            <el-table-column
                align="center"
                prop="settleCode"
                label="类别编码"
                width="200"
            >
            </el-table-column>
            <el-table-column
                align="center"
                prop="settleName"
                label="类别名称"
                width="200"
            >
            </el-table-column>
            <el-table-column
                align="center"
                prop="sequenceNo"
                label="排序号"
                width="200"
            >
            </el-table-column>
            <el-table-column
                align="center"
                prop="delMark"
                label="删除状态"
                width="200"
                show-overflow-tooltip
            >
            <template slot-scope="scope">{{ scope.row.delMark==1?'正常':'已删除' }}</template>
            </el-table-column>
            <el-table-column align="center" label="操作" show-overflow-tooltip>
                <template slot-scope="scope">
                <el-button type="primary" size="mini" @click="updateInfo(scope.row)">修改</el-button>
                <el-button type="danger" size="mini" @click="removeInfo(scope.row.id)"
                    >删除</el-button
                >
                </template>
            </el-table-column>
        </el-table>
            <!-- 分页器 -->
        <el-pagination
            style="margin-top: 2%;text-align: center;"
            background
            layout="total, prev, pager, next, jumper"
            :page-size="limit"
            :current-page="page"
            :total="total"
            @current-change="getList"
        >
        </el-pagination>
        <!-- 添加表单 -->
        <el-dialog title="添加类别" :visible.sync="dialogFormVisible">
            <el-form :model="addForm">
                <el-form-item label="类别编码" label-width="120px">
                <el-input v-model="addForm.settleCode" autocomplete="off"></el-input>
                </el-form-item>
                <el-form-item label="类别名称" label-width="120px">
                <el-input v-model="addForm.settleName" autocomplete="off"></el-input>
                </el-form-item>
                <el-form-item label="顺序号" label-width="120px">
                <el-input v-model="addForm.sequenceNo" autocomplete="off" type="number" style="width: 120px;"></el-input>
                </el-form-item>
            </el-form>
            <div slot="footer" class="dialog-footer">
                <el-button @click="addVisible">取 消</el-button>
                <el-button type="primary" @click="addItem"
                >确 定</el-button
                >
            </div>
        </el-dialog>
        <!-- 修改表单 -->
        <el-dialog title="修改类别" :visible.sync="dialogFormVisible2">
            <el-form :model="updateForm">
                <el-form-item label="类别编码" label-width="120px">
                <el-input v-model="updateForm.settleCode" autocomplete="off"></el-input>
                </el-form-item>
                <el-form-item label="类别名称" label-width="120px">
                <el-input v-model="updateForm.settleName" autocomplete="off"></el-input>
                </el-form-item>
                <el-form-item label="显示顺序号" label-width="120px">
                <el-input v-model="updateForm.sequenceNo" autocomplete="off" type="number" style="width: 120px;"></el-input>
                </el-form-item>
            </el-form>
            <div slot="footer" class="dialog-footer">
                <el-button @click="dialogFormVisible2 = false">取 消</el-button>
                <el-button type="primary" @click="updateItem"
                >确 定</el-button
                >
            </div>
        </el-dialog>
    </div>
</template>

<script>
import settlecategory from "@/api/his/settlecategory"
export default {
    created() {
        this.getList()
    },
    data() {
        return {
            keyword:"",
            list: null, // 数据列表
            total: 0, // 总记录数
            page: 1, // 页码
            limit: 8, // 每页记录数
            updateForm:{
                settleCode:null,
                settleName:null,
                sequenceNo:null,
                id:null
            },
            addForm:{               
                settleCode:null,
                settleName:null,
                sequenceNo:null,   
            },
            dialogFormVisible:false,
            dialogFormVisible2:false
        }
    },
    methods: {
        removeInfo(id){
            settlecategory.delSettleCategoryById(id)
            .then(res=>{
                console.log(res)
                this.$message({
                    type: "success",
                    message: "删除成功!",
                });
                this.getList()
            }).catch(err=>{
                console.log(err)
                this.$message({
                    type: "error",
                    message: "删除失败!",
                });
            })
        },
        addItem(){
            settlecategory.addSettleCategory(this.addForm)
            .then(res=>{
                console.log(res)
                this.$message({
                    type: "success",
                    message: "修改成功!",
                });
                this.addVisible()
                this.getList();
            }).catch(err=>{
                console.log(err)
            })
        },
        addVisible(){
            this.dialogFormVisible = false
            this.addForm = {               
                settleCode:null,
                settleName:null,
                sequenceNo:null,   
            }
        },
        updateItem(){
            settlecategory.updateSettleCategory(this.updateForm)
            .then(res=>{
                console.log(res)
                    this.$message({
                    type: "success",
                    message: "修改成功!",
                });
                this.dialogFormVisible2 = false
                this.getList();
            }).catch(err=>{
                console.log(err)
                this.$message({
                    type: "error",
                    message: "修改失败!",
                });
            })
        },
        updateInfo(scope){
            this.dialogFormVisible2 = true
            this.updateForm = {
                settleCode:scope.settleCode,
                settleName:scope.settleName,
                sequenceNo:scope.sequenceNo,
                id:scope.id
            }
        },
        getList(page = 1) {
            this.page = page;
            settlecategory
                .getSettleCategoryListPage(this.page,this.limit,this.keyword)
                .then((res) => {
                console.log(res);
                this.list = res.data.data.list;
                this.total = res.data.data.total;
                console.log(this.list);
                }) //请求成功
                .catch((error) => {
                console.log(error);
                }); //请求失败
        },
    },
}
</script>

<style scoped>

</style>